package entityBeans;
import java.util.Collection;
import java.util.ArrayList;
import java.io.Serializable;
import javax.persistence.*;

@Entity
public class Usuario implements Serializable {
    private static final long serialVersionUID = 1L;
    
    private Long id;
    private String rut;
    private String username;
    private String password;
    private String realname;
    private String direccion;
    private String telefono;
    private String email;
    private boolean tipo;   //==true, es un admin
    private boolean estado; //==true, esta activo, ==false -> estA CADUCADO
    private java.util.Date timeCreated;
    private Collection<Compra> compras;
    private Collection<Arriendo> arriendos;

    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public String getRut( ) {
        return rut;
    }
    public void setRut(String rut) {
        this.rut = rut;
    }

    public String getUsername( ) {
        return username;
    }
    public void setUsername(String username) {
        this.username = username;
    }

    public String getPassword( ) {
        return password;
    }
    public void setPassword(String password) {
        this.password = password;
    }

    public String getRealname( ) {
        return realname;
    }
    public void setRealname(String realname) {
        this.realname = realname;
    }

    public String getDireccion( ) {
        return direccion;
    }
    public void setDireccion(String direccion) {
        this.direccion = direccion;
    }

    public String getTelefono( ) {
        return telefono;
    }
    public void setTelefono(String telefono) {
        this.telefono = telefono;
    }

    public String getEmail( ) {
        return email;
    }
    public void setEmail(String email) {
        this.email = email;
    }

    public boolean isTipo( ) {
        return tipo;
    }
    public void setTipo(boolean tipo) {
        this.tipo = tipo;
    }
    public boolean isEstado( ) {
        return estado;
    }
    public void setEstado(boolean estado) {
        this.estado = estado;
    }

    @Temporal(TemporalType.TIME)
    public java.util.Date getTimeCreated( ) {
    	return timeCreated;
    }
    public void setTimeCreated(java.util.Date time) {
    	timeCreated = time;
    }
    @OneToMany(cascade={CascadeType.ALL})
    public Collection<Compra> getCompras(){
        return compras;
    }
    public void setCompras(ArrayList<Compra> compras){
        this.compras=compras;
    }

    @OneToMany(cascade={CascadeType.ALL})
    public Collection<Arriendo> getArriendos(){
        return arriendos;
    }
    public void setArriendos(ArrayList<Arriendo> arriendos){
        this.arriendos=arriendos;
    }
    @Override
    public int hashCode() {
        int hash = 0;
        hash += (id != null ? id.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Usuario)) {
            return false;
        }
        Usuario other = (Usuario) object;
        if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "entityBeans.Usuario[id=" + id + "]";
    }

}
